<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise</title>
</head>

<body>
    <script>
        var add = function() {
            var a = 10,
                b = 20;
            return new Promise(
                function(resolve, reject) {
                    setTimeout(function() {
                        console.log("a+b=" + (a + b));
                        resolve(a + b);;
                    }, 1000)
                }
            )
        }
        var multiply = function(data) {
            bear = data;
            // console.log(bear);
            return new Promise(
                function(resolve, reject) {
                    setTimeout(function() {
                        console.log("(a+b)*3=" + (bear * 3));
                        resolve(bear * 3);
                    }, 1000)
                }
            )
        }
        var subtraction = function(data) {
            bear = data;
            // console.log(bear);
            return new Promise(
                function(resolve, reject) {
                    setTimeout(function() {
                        console.log("(a+b)*3-6=" + (bear - 6));
                    }, 1000)
                }
            )
        }
        add().then(multiply).then(subtraction);
    </script>
</body>

</html>